# 集合：特点不重复，无序
# 定义空集合
mySet = set()
print("空集合", mySet)
mySet = {"张三", "李四", "张三", "123", "hello"}
print(mySet)
# 添加新元素
mySet.add("python")
mySet.add("python")
mySet.add("python")
print(mySet)
# 移除元素
mySet.remove("张三")
print(mySet)
# 随机取出一个元素,取出后会改变元素
element = mySet.pop()
print(f"随机取出的元素是：{element}")
print(f"mySet的值：{mySet}")

mySet1 = {"张三", "hello", "qqq"}
# 交集
print("交集", mySet1 & mySet1)

# mySet中有的，mySet1没有的
newSet = mySet.difference(mySet1)
# 取2个集合的差集，得到一个新的结合，2个集合本身不变
print(f"mySet1的值：{mySet1}")
print(f"newSet的值：{newSet}")
# 消除两个差集
# mySet中有的，mySet1有这个元素就消除
mySet = {"1", "2", "3", "4", "5"}
mySet1 = {"2", "5", "6"}
newSet = mySet.difference(mySet1)
print(f"mySet的值：{mySet}")
print(f"mySet1的值：{mySet1}")
print(f"newSet的值：{newSet}")
# 2个集合合并
newSet = mySet.union(mySet1)
print(f"newSet的值：{newSet}")
# 统计元素的数量
print(len(newSet))
# 遍历集合
for ele in mySet:
    print(ele, end="   ")
print()
# 清空集合
mySet.clear()
print(mySet)